import Vue from 'vue'
import VueRouter from 'vue-router'
import config from './config.js'
import store from '@/store'


//1、vue安装vue-router
Vue.use(VueRouter);

var router = new VueRouter(config);


router.beforeEach(function(to,from,next){
    if(to.meta.auth){
        // console.log(11111111111111);
        // console.log(to.meta.auth);
        // console.log(store.state.loginUser.menuList);
        // console.log(store.state.loginUser.menuList[3].childrenMenus[1].auth);
        // console.log(store.state.loginUser.menuList.filter(item=>item.childrenMenus[0].auth==to.meta.auth).length);
        // console.log(11111111111111);
        if(store.state.loginUser.menuList.filter(item=>item.auth==to.meta.auth).length>0){
            next();
        }
        // if(store.state.loginUser.menuList.filter((item)=>{
        //     var flag = false;
        //     for (let index = 0; index < item.length; index++) {
        //         if (item[index].auth == to.meta.auth){
        //             flag=true;
        //         }
        //     }
        //     return flag;
        // })){
        //     next();
        // }
        // else if(store.state.loginUser.menuList[3].childrenMenus[1].auth==to.meta.auth){
        //     next();
        // }
        else{
            next({name:"404", params: { '0': '404' }});
        }
    }else{
        next();
    }
});

//2、vue-router需要配置，简单来说需要配置路径和组件之间的映射关系

export default router;
